home *** CD-ROM | disk | FTP | other *** search
/ AMIGA-CD 2 / Amiga-CD - Volume 2.iso / ungepackte_daten / 1993 / 3 / 02 / tips & tricks / autoremove.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-01  |  2.2 KB  |  54 lines

  1. /*
  2.  * AutoRemove.c
  3.  * Compilieren mit DICE: dcc AutoRemove.c -o AutoRemove
  4.  */
  5. #include <intuition/intuition.h>
  6. struct IntuitionBase *IntuitionBase;
  7. struct NewWindow NewWindow= {
  8.   40,50,550,75,0,1,0,WINDOWDRAG|WINDOWDEPTH,0,0,
  9.   (UBYTE *)0,0,0,0,0,0,0,WBENCHSCREEN };
  10. struct IntuiText IText={1,0,0,25,35,0,
  11.   "Zum Entfernen des Fensters 'AutoRemove' nochmal aufrufen !",
  12.   0};
  13. struct Window *Window;
  14. struct IntuiMessage *IntuiMessage;
  15. struct MsgPort NewPort,*OldPort,ReplyPort;
  16. struct Message MsgSend,*MsgReceive;
  17. void main() {
  18.  if (OldPort=(struct MsgPort *)FindPort("AutoRemove Port")) {
  19.   /* Programm schon im Speicher ? */
  20.   ReplyPort.mp_Node.ln_Pri=0;  /* Nachricht an gemeinsamen Port */
  21.   ReplyPort.mp_Node.ln_Name="AutoRemove ReplyPort"; /* schicken */
  22.   ReplyPort.mp_SigTask=(APTR)FindTask(0);
  23.   AddPort(&ReplyPort);                 /* Reply-Port einrichten */
  24.   MsgSend.mn_Length=sizeof(struct Message);        /* Nachricht */
  25.   MsgSend.mn_Node.ln_Type=NT_MESSAGE;         /* initialisieren */
  26.   MsgSend.mn_ReplyPort=&ReplyPort;
  27.   PutMsg(OldPort,&MsgSend);              /* Message verschicken */
  28.   WaitPort(&ReplyPort);                   /* auf Antwort warten */
  29.   RemPort(&ReplyPort);    /* Reply-Port entf. und Programm verl.*/
  30.  }
  31.  else {
  32.    /* wenn Programm noch nicht im Speicher: Fenster öffnen und  */
  33.    /* auf Nachricht warten */
  34.   if (IntuitionBase=(struct IntuitionBase *)
  35.     OpenLibrary("intuition.library",0)) {
  36.    if (Window=(struct Window *)
  37.     OpenWindow(&NewWindow)) { /* Fenster öffnen */
  38.     PrintIText(Window->RPort,&IText,0,0);
  39.     NewPort.mp_Node.ln_Pri=0;               /* Port für spätere */
  40.                                 /* Kommunikation initialisieren */
  41.     NewPort.mp_Node.ln_Name="AutoRemove Port";
  42.     NewPort.mp_SigTask=(APTR)FindTask(0);      /* An Port-Liste */
  43.     AddPort(&NewPort);                               /* anfügen */
  44.     WaitPort(&NewPort);                 /* Auf Nachricht warten */
  45.     MsgReceive=(APTR)GetMsg(&NewPort);   /* Nachricht entfernen */
  46.     ReplyMsg(MsgReceive);                    /* und beantworten */
  47.     RemPort(&NewPort);                 /* Port wieder entfernen */
  48.     CloseWindow(Window);               /* und Fenster schließen */
  49.    }
  50.    CloseLibrary(IntuitionBase);
  51.   }
  52.  }
  53. }
  54.